/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tree;

/**
 *
 * @author Ej-Dý
 */
/**
 * Vnitrni forma: identifikator.
 */
public class IdentifierFunTree extends VyrazTree {

    private String name;
    private VariableFunTree variable;
    private Argument2Tree arg;



    /**
     * Je identifikator na leve strane prirazeni?
     */
    private boolean leftValue;

    public IdentifierFunTree(Position start, Position end, String name,Argument2Tree arg) {
        super(start, end);
        this.name = name;
        this.arg=arg;
    }

    public String getName() {
        return name;
    }

    public VariableFunTree getVariable() {
        return variable;
    }
     public Argument2Tree getArg() {
        return arg;
    }

    public void setVariable(VariableFunTree v) {
        this.variable = v;
    }

    

    public boolean isLeftValue() {
        return leftValue;
    }

    public void setLeftValue(boolean leftValue) {
        this.leftValue = leftValue;
    }

    public int getSlot() {
        return variable.getSlot();
    }



    @Override
    public void accept(TreeVisitor visitor) {
        visitor.visitIdentifierFun(this);
    }

    @Override
    public void generate(Context ctx) {
       arg.generate(ctx);
       ctx.print("invoke "+name+" "+variable.getArg().getPocet());
       ctx.println("");
    }

    @Override
    public String toString() {
        return String.format("IdentifierFun %s: '%s'", super.toString(), name);
    }

    @Override
    public Type getType() {
        return variable.getType();
    }
}
